
package mdoc.ejbsample;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Table;
import javax.persistence.NamedQuery;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.OneToMany;
import javax.persistence.FetchType;
import javax.persistence.CascadeType;

import java.util.*;

@Entity
@Table(name = "SALLES_PROG", schema = "test")
@NamedQuery(name = "findAllSallesProg", query = "select s from SalleProg s")
public class SalleProg implements java.io.Serializable {
    private static final long serialVersionUID = -3L;
    
    @Id @GeneratedValue(strategy = GenerationType.AUTO)
	private int id;
    
    @ManyToOne @JoinColumn(name = "film_id")
	private Film film;
    
    @OneToMany(mappedBy = "salleprog", fetch=FetchType.EAGER, cascade=CascadeType.ALL)
	private Set<Seance> seances;
    
    @OneToOne @JoinColumn(name = "salle_id")
    private Salle salle;
   
    public int getId() {
	return id;
    }

    public Film getFilm() {
	return film;
    }

    public HashSet<Seance> getSeance(){
	return new HashSet<Seance>(seances);
    }
    
    public void setFilm(Film film) {
	this.film = film;
    }
    
    @Override public String toString() {
	StringBuilder sb = new StringBuilder();
	sb.append("Salle[id=").append(getId()).append(", film=").append(getFilm()).append("]");
	return sb.toString();
    }

	public void setSalle(Salle salle) {
		this.salle = salle;
	}

	public Salle getSalle() {
		return salle;
	}
}
